
//验证码函数
function changeKeyCode(){
	//声明一个变量，为0，用来接收生成的随机字符串
	var result = 0;
	//变量内容赋值为随机的数字组成的字符串
	result = parseInt(Math.random() * 10000).toString();
	//判断随机数的格式是否正确
	if(result.length > 5){
		result -= 1;
		return;
	}else if(result.length == 3){
		result = "0" + result;
		return;
	}else if(result.length == 2){
		result = "00" + result;
		return;
	}else if(result.length == 1){
		result = "000" + result;
		return;
	}
	//将变量写入验证码html标签中
	$("#keyBox").text(result);
	//设置验证码标签的样式
	$("#keyBox").css('text-indent','1em');
	$("#keyBox").css('font-size','20px');
	$("#change_key").css('margin-left','20px');
}

//跳转登录页面的函数
function changePage(){
	$(window).attr('location','/Users/qingyun/Desktop/git_caesar_item/20190409/page01.html');
}
//跳转注册页面的函数
function changePage2(){
	$(window).attr('location','/Users/qingyun/Desktop/git_caesar_item/20190409/page02.html');
}
//跳转首页的函数
function changePage3(){
	$(window).attr('location','file:///Users/qingyun/Desktop/git_caesar_item/20190409/page03.html')
}
//跳转个人中心的函数
function changePage4(){
	$(window).attr('location','file:///Users/qingyun/Desktop/git_caesar_item/20190408/test01.html')
}
//微博的接口前缀
var firstUrl = "http://39.105.222.9:8095/";
//微博的注册接口后缀
var regUrl = "blog/reg_user/";
//微博的登录后的接口后缀
var loginUrl = "blog/login_user/";
//微博的登出后的接口后缀
var logoutUrl = "blog/logout_user/";
//微博获取到接口中所有人微博的后缀
var allBlog = "blog/query_blog/";
//微博中自己的微博接口的后缀
var myBlog = "blog/query_self_blog/";
//微博中添加微博的接口的后缀
var publicBlog = "blog/add_blog/";
//微博中删除微博的接口后缀
var deleteBlog = "blog/del_blog/";
//微博中关注用户的接口后缀
var myfollows = "blog/query_user_blog/";
//注销登录的函数
function logout(){
	var url = firstUrl + logoutUrl;
	var param = {token: sessionStorage.token};
	$.post(url, param, function(d){
		if(d.result == 1){
			// 删除本地token
			sessionStorage.removeItem("token");
			changePage();
		}else{
			return;
		}
	});
}
//获取微博的函数
function loadBlog(datas,selector){
	datas.forEach(function(obj,index){
		var liList = $("<li id='" + obj.id + "'></li>");
		liList.appendTo($(selector));

		liList.append("<div class='faceDiv'><img src ='" + obj.portrait + "'></div>");
		liList.append("<div class='right'><p class='say'><a href='#'>" + obj.username + " " + obj.nickname + "</a><p>" + obj.content + "</p><p class='time'></p></p></div>");
	});
}


